package com.gao.modules.sender;

import com.gao.modules.email.Email;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author anshenghui
 * @date 2021/10/31 21:42
 * @desc 消费方 mq
 */
@Component
@Slf4j
public class RabbitListerHandler {

    @Autowired
    private Email email;

    @RabbitListener(queues = "VerifyCodeDirectQueue")
    @RabbitHandler
    public void listen01(Map code) {
        log.info("接收到的时间为：" + String.valueOf(System.currentTimeMillis()));
        String address = (String) code.get("Address");
        String userName = (String) code.get("userName");
        String verifyCode = (String) code.get("verifyCode");
        email.sendEmail(address,"来自高总系统的验证码","您好" + userName + ": \n您的验证码为" + verifyCode + "\n有效时间为5分钟,请及时使用。");
    }

//    /**
//     * 验证码
//     * @param code
//     */
//    @RabbitListener(queues = "verifyCodeDirectQueueCode")
//    @RabbitHandler
//    public void listen01Code(Map code) {
//        code.get("verifyCode");
//        log.info("接收到的时间为：" + String.valueOf(System.currentTimeMillis()));
//        System.out.println(code.toString());
//    }
}
